package com.gagakuai.test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/*
 * @program: settement
 * @description:
 * @author: houhong
 * @create: 2022-11-10 23:18
 */
public class CountDownlatchDemo {

    private static CountDownLatch countDownLatch = new CountDownLatch(1);
    private static AtomicInteger total = new AtomicInteger(0);

    public static void main(String[] args) throws Exception {

        for (int i = 0; i < 10; i++) {

            new Thread(() -> {

                try {
                    countDownLatch.await();
                    for (int j = 0; j < 1000; j++) {

                        total.getAndIncrement();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();

        }
        Thread.sleep(1000);
        countDownLatch.countDown();
        Thread.sleep(1000);
        System.out.println(total);
    }


}